#include<bits/stdc++.h>
#define int long long
namespace IO{
    template<typename T>
    void read(T &x){
        char ch=getchar();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getchar();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getchar();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    template <typename _Tp>
    void write(_Tp x) {
        if(x<0) x=(~x+1),putchar('-');
        if(x>9) write(x/10);
        putchar(x%10+'0');
    }
}
using namespace std;
using namespace IO;
const int N=2e5+5,mod=998244353;
int n;
set<int> s;
signed main() {
#ifndef KAxdd
#ifndef ONLINE_JUDGE
    freopen("kte.in","r",stdin);
    freopen("kte.out","w",stdout);
#endif
#endif
    read(n);
    int Sum=0;
    while(n--) {
        int x; read(x);
        if(s.find(x)!=s.end()) s.erase(x),Sum-=x;
        else s.insert(x),Sum+=x;
        if(s.size()<=8e7/n) {
            auto l=s.begin(); auto r=s.rbegin();
            int suml=0,sumr=0,sum=0,nowl=0;
            while(true) {
                if(l==s.end()) break;
                suml+=*l; sumr+=*r;
                sum+=sumr-max(nowl,suml);
                nowl=max(nowl,sumr);  l++; r++;         
            }
            printf("%lld\n",sum);
        } else printf("%lld\n",Sum-2*(*s.begin()));
    }
    return 0;
}